package com.wingsoft.work.controller;

import com.wingsoft.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.Page;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wingsoft.common.annotation.Log;
import com.wingsoft.common.core.controller.BaseController;
import com.wingsoft.common.core.domain.AjaxResult;
import com.wingsoft.common.enums.BusinessType;
import com.wingsoft.work.domain.Activation;
import com.wingsoft.work.dto.ActivationDto;
import com.wingsoft.work.vo.ActivationVo;
import com.wingsoft.work.service.impl.ActivationServiceImpl;
import com.wingsoft.common.utils.poi.ExcelUtil;

/**
 * 激活码Controller
 *
 * @author hemj
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/work/activation")
public class ActivationController extends BaseController
{
    @Autowired
    private ActivationServiceImpl activationService;

    /**
     * 统计数量激活码
     */
    //@PreAuthorize("@ss.hasPermi('work:activation:list')")
    @PostMapping("/count")
    public R<Long> count(@RequestBody ActivationDto activationDto)
    {
        Long num = activationService.countList(activationDto);
        return R.ok(num);
    }

    /**
     * 分页查询激活码
     */
    @PreAuthorize("@ss.hasPermi('work:activation:list')")
    @PostMapping("/list")
    public R<List<ActivationVo>> list(@RequestBody ActivationDto activationDto)
    {
        Page page = startPage();
        List<ActivationVo> list = activationService.queryList(activationDto);
        return getResDataTable(list,page);
    }

    /**
     * 查询激活码列表
     */
    @PreAuthorize("@ss.hasPermi('work:activation:list')")
    @PostMapping("/query")
    public R<List<ActivationVo>> query(@RequestBody ActivationDto activationDto)
    {
        List<ActivationVo> list = activationService.queryList(activationDto);
        return R.ok(list);
    }

    /**
     * 导出激活码
     */
    //@PreAuthorize("@ss.hasPermi('work:activation:export')")
    @Log(title = "导出激活码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivationDto activationDto)
    {
        List<ActivationVo> list = activationService.queryList(activationDto);
        ExcelUtil<ActivationVo> util = new ExcelUtil<ActivationVo>(ActivationVo.class);
        util.exportExcel(response, list, "激活码数据");
    }

    /**
     * 获取激活码详细信息
     */
    //@PreAuthorize("@ss.hasPermi('work:activation:query')")
/*    @PostMapping(value = "/get")
    @ApiOperation("获取激活码详细信息")
    public R<ActivationVo> getInfo(@RequestBody ActivationDto activationDto)
    {
        return R.ok(activationService.getOneById(activationDto.getId()));
    }*/

    /**
     * 新增激活码
     */
    @PreAuthorize("@ss.hasPermi('work:activation:add')")
    @Log(title = "新增激活码", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addFast")
    public R addFastv(@RequestBody ActivationDto activationDto)
    {
        activationService.addFast(activationDto);
        return R.ok();
    }


    @PreAuthorize("@ss.hasPermi('work:activation:addAdmin')")
    @Log(title = "新增激活码", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addAdmin")
    public R addAdmin(@RequestBody ActivationDto activationDto)
    {
        activationService.addAdmin(activationDto);
        return R.ok();
    }

   /* *//**
     * 修改激活码
     *//*
    //@PreAuthorize("@ss.hasPermi('work:activation:edit')")
    @Log(title = "修改激活码", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    @ApiOperation("修改激活码")
    public R edit(@RequestBody ActivationDto activationDto)
    {
        return R.ok(activationService.updateCascade(activationDto));
    }

    *//**
     * 删除激活码
     *//*
    //@PreAuthorize("@ss.hasPermi('work:activation:remove')")
    @Log(title = "删除激活码", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    @ApiOperation("删除激活码")
    public R remove(@PathVariable Long[] ids)
    {
        activationService.removeByIdList(Arrays.asList(ids));
        return R.ok();
    }*/
}
